home *** CD-ROM | disk | FTP | other *** search
/ Reverse Code Engineering RCE CD +sandman 2000 / ReverseCodeEngineeringRceCdsandman2000.iso / RCE / Ebooks / Thinking in C++ V2 / C19 / TemplateTemplate.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2000-05-25  |  804 b   |  35 lines

  1. //: C19:TemplateTemplate.cpp
  2. // From Thinking in C++, 2nd Edition
  3. // Available at http://www.BruceEckel.com
  4. // (c) Bruce Eckel 1999
  5. // Copyright notice in Copyright.txt
  6. #include <vector>
  7. #include <iostream>
  8. #include <string>
  9. using namespace std;
  10.  
  11. // As long as things are simple, 
  12. // this approach works fine:
  13. template<typename C>
  14. void print1(C& c) {
  15.   typename C::iterator it;
  16.   for(it = c.begin(); it != c.end(); it++)
  17.     cout << *it << " ";
  18.   cout << endl;
  19. }
  20.  
  21. // Template-template argument must 
  22. // be a class; cannot use typename:
  23. template<typename T, template<typename> class C>
  24. void print2(C<T>& c) {
  25.   copy(c.begin(), c.end(), 
  26.     ostream_iterator<T>(cout, " "));
  27.   cout << endl;
  28. }
  29.  
  30. int main() {
  31.   vector<string> v(5, "Yow!");
  32.   print1(v);
  33.   print2(v);
  34. } ///:~
  35.